﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Budget.DataAccess;
using Budget.DataAccess.Services;
using Budget.DataAccess.Repository;

namespace Budget.WCF
{
	// NOTE: If you change the class name "IncomeService" here, you must also update the reference to "IncomeService" in App.config.
	public class IncomeService : IIncomeService
	{
		#region Private Members

		private IIncomeDataService svc;
		//IRepository<Income> _incomeRepository;
		//BudgetDataContext db;

		#endregion

		public IncomeService() { }

		public IncomeService( IIncomeDataService incomeService )
		{
			svc = incomeService;
		}

		#region IIncomeService Members

		public IList<Income> GetAll()
		{
			IList<Income> incomes;

			if ( svc == null )
			{
				svc = new IncomeDataService( new BudgetRepository<Income>( new BudgetDataContext() ) );
			}
			incomes = svc.GetAll();

			return incomes;
		}

		public Income GetIncomeById( int ID )
		{
			Income income;

			if ( svc == null )
			{
				svc = new IncomeDataService( new BudgetRepository<Income>( new BudgetDataContext() ) );
			}
			income = svc.GetById( ID );

			return income;
		}

		public void Save( Budget.DataAccess.Income income )
		{
			// validation will go here

			svc = new IncomeDataService( new BudgetRepository<Income>( new BudgetDataContext() ) );
			svc.Save( income );
		}

		public decimal GetTotalIncome()
		{
			svc = new IncomeDataService( new BudgetRepository<Income>( new BudgetDataContext() ) );
			return svc.GetTotalIncome();
		}

		#endregion
	}
}
